from django.contrib.auth.models import User
from django.db import models
from datetime import date

class Level(models.Model):
    name = models.CharField(max_length=20)
    discount_rate = models.FloatField(default=1.0)

    def __unicode__(self):
        return self.name

class Member(models.Model):
    GENDER_CHOICES = (
        ('M', 'Male'),
        ('F', 'Female'),
        ('O', 'Other'),
    )
    user = models.OneToOneField(User, related_name='info')
    level = models.ForeignKey(Level)
    name = models.CharField(max_length=50)
    gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
    birthday = models.DateField()
    register_date = models.DateField()
    expire_date = models.DateField()
    balance = models.FloatField(default=0)

    def is_active(self):
        return date.today() < self.expire_date

    def __unicode__(self):
        return self.user.username + ' : ' + str(self.level)

class Address(models.Model):
    country = models.CharField(max_length=100)
    state = models.CharField(max_length=50)
    city = models.CharField(max_length=50)
    street = models.CharField(max_length=200)
    member = models.OneToOneField(Member, related_name='address')

    def __unicode__(self):
        return self.street + '/' + self.city + '/' + self.state + '/' + self.country

    class Meta:
        verbose_name_plural = 'Addresses'
